// 基础设施-潜在客户管理
import r from '@/utils/request';
import type { ResponseType, ListParams, ListResponseType } from '../types';

enum API {
    customerList = '/customer/list', // 潜在客户列表
    customerDelete = '/customer/delete', // 删除潜在客户
    customerDeleteAll = '/customer/deleteAll', // 批量删除潜在客户
    customerGet = '/customer/get', // 获取单条客户信息
    customerAdd = '/customer/add', // 潜在客户添加
    customerUpdate = '/customer/update', // 潜在客户修改
}

// 潜在客户列表参数
interface customerListParams extends ListParams {
    name: string;
    idCard: string;
    beginDate: string;
    state: number;
    endDate: string;
}

// 潜在客户列表返回值
type customerListRes = ListResponseType<{
    id: number;
    companyId: number;
    name: string;
    mobile: string;
    gender: number;
    birthday: string;
    status: string;
    idCard: string;
    roomRequire: string;
    content: string;
    state: number;
    source: string;
    addTime: string;
    addAccountId: number;
    addAccountName: string;
    stateName: string;
    family: string;
}>

// 潜在客户列表接口
export function customerListAPI(params: customerListParams): Promise<customerListRes> {
    return r.get(API.customerList, params)
}

// 删除潜在客户接口
export function customerDeleteAPI(id: number): Promise<ResponseType<string>> {
    return r.delete(API.customerDelete + '/' + id)
}

// 批量删除潜在客户接口
export function customerDeleteAllAPI(ids: number[]): Promise<ResponseType<string>> {
    return r.post(API.customerDeleteAll,ids)
}

// 获取单条客户信息family
interface customerGetItem {
    id: number;
    customerId: number;
    name: string;
    mobile: string;
    idCard: string;
    relation: string;
    gender: number;
    address: string;
}

// 获取单条客户信息返回值
export type customerGetRes = {
    id: number;
    companyId: number;
    name: string;
    mobile: string;
    gender: number | null;
    birthday: string;
    status: string;
    idCard: string;
    roomRequire: string;
    content: string;
    state: number | null;
    source: string;
    addTime: string;
    addAccountId: number | null;
    addAccountName: string;
    stateName: string;
    family: customerGetItem[];
}

// 获取单条客户信息接口
export function customerGetAPI(id: number): Promise<ResponseType<customerGetRes>> {
    return r.get(API.customerGet + '/' + id)
}



// 潜在客户添加family
interface customerAddItem {
    id: number;
    customerId: number;
    name: string;
    mobile: string;
    idCard: string;
    relation: string;
    gender: number;
    address: string;
    state: 1,
    source: "在线咨询",
}

// 潜在客户添加返回值
type customerAddRes = ResponseType<{
    id: number;
    companyId: number;
    name: string;
    mobile: string;
    gender: number;
    birthday: string;
    status: string;
    idCard: string;
    roomRequire: string;
    content: string;
    state: number;
    source: string;
    addTime: string;
    addAccountId: number;
    addAccountName: string;
    stateName: string;
    family: customerAddItem[];
}>

// 潜在客户添加接口
export function customerAddAPI(params:customerAddItem): Promise<customerAddRes> {
    return r.post(API.customerAdd,params)
}



// 潜在客户修改family
interface customerUpdateItem {
    id: number;
    customerId: number;
    name: string;
    mobile: string;
    idCard: string;
    relation: string;
    gender: number;
    address: string;
}

// 潜在客户修改参数
interface customerUpdateParams {
    id: number;
    companyId: number;
    name: string;
    mobile: string;
    gender: number;
    birthday: string;
    status: string;
    idCard: string;
    roomRequire: string;
    content: string;
    state: number;
    source: string;
    addTime: string;
    addAccountId: number;
    addAccountName: string;
    stateName: string;
    family: customerUpdateItem[];
}

// 潜在客户修改返回值
type customerUpdateRes = ResponseType<{
    id: number;
    companyId: number;
    name: string;
    mobile: string;
    gender: number;
    birthday: string;
    status: string;
    idCard: string;
    roomRequire: string;
    content: string;
    state: number;
    source: string;
    addTime: string;
    addAccountId: number;
    addAccountName: string;
    stateName: string;
    family: customerUpdateItem[];
}>

// 潜在客户修改接口
export function customerUpdateAPI(params: customerUpdateParams): Promise<customerUpdateRes> {
    return r.put(API.customerUpdate, params)
}